
public class ArrayList<T>{
	
	private int MAX_Length;
	private Object[] store;
	private int loc;
	
	public ArrayList(){
		MAX_Length = 10;
		store = new Object[MAX_Length];
		loc = 0;
	}
	
	public boolean add(T e){
		if(loc < MAX_Length){
			store[loc ++] = e;
			return true;
		}
		
		MAX_Length *= 2;
		Object[] temp = new Object[MAX_Length];
		copy(store,temp,loc);
		store = temp;
		store[loc ++] = e;
		return true;
	}

	@SuppressWarnings("unchecked")
	public T get(int i){
		if(i >= loc || i < 0){
			throw new IndexOutOfBoundsException(i+""); 
		}
		
		return (T)store[i];
		
	}
	
	public T set(int i,T e){
		if(i >= loc || i < 0){
			throw new IndexOutOfBoundsException(i+""); 
		}
		store[i] = e;
		return e;
	}
	
	@SuppressWarnings("unchecked")
	public T del(int i){
		if(i >= loc || i < 0){
			throw new IndexOutOfBoundsException(i+""); 
		}
		
		T temp = (T)store[i];
		
		move(store,i+1,loc);
		
		loc--;
		
		return temp;
		
	}
	
	private void move(Object[] store, int i, int loc) {
		for(;i < loc;i ++){
			store[i-1] = store[i];
		}
	}

	public int size(){
		return loc;
	}
	
	private void copy(Object[] store, Object[] temp, int loc) {
		for(int i = 0;i < loc;i ++){
			temp[i] = store[i];
		}
	}
	
}
